# @Author: 唐奇才
# @Time: 2021/5/4 14:36
# @File: testSpider.py
# @Software: PyCharm

import json
import myUtils.myFakerHeaders as mfh
import requests
import myUtils.myJsonUtil as mju

page = 1
oid = 672756810
cb = "jQuery1720717671480774899_1620107047887"

baseURL = "https://api.bilibili.com/x/v2/reply/main?" \
          "callback={}" \
          "&oid={}" \
          "&type=1" \
          "&next={}"


def getHTML(url):
    headers = {'User-Agent':mfh.getFakeHeaders()}
    proxy = mfh.getFakeProxy()
    result = requests.get(url, headers, proxies=proxy,timeout=10)
    # print(result.text)
    return result.text



def getJsonDataFrom(data):
    jsonData = json.loads(data)
    return jsonData


def saveJsonData(path, data):
    mju.saveJsonData(path, jsonData=data)

def getDetailDataFromJson():
    pass


def main():
    data = getHTML(baseURL.format(str(cb), str(oid), str(page)))
    print(data)
    # print(data, type(data))
    jdata = getJsonDataFrom(data)
    # print(jdata)
    print("----------------------")
    # print(jdata["data"]["replies"])
    # jdata = jdata["data"]["replies"]
    saveJsonData("./test.json",jdata)
    # getHTML("https://www.baidu.com")

if __name__ == '__main__':
    main()
